/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package session;

import entites.CompteBancaire;
import java.util.List;
import javax.ejb.Stateless;
import javax.ejb.LocalBean;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author FANNY
 */
@Stateless
@LocalBean
public class GestionnaireDeCompteBancaire {
    @PersistenceContext(unitName = "TP3BanqueFA-ejbPU")
    private EntityManager em;

    
    // Add business logic below. (Right-click in editor and choose
    // "Insert Code > Add Business Method")
    
    public void creerCompte(CompteBancaire c){
        em.persist(c);
    }

    public void persist(Object object) {
        em.persist(object);
    }
    
    public List<CompteBancaire> getAllComptes(){
        Query q = em.createNamedQuery("CompteBancaire.findAll");
        return q.getResultList();        
    }
    
    public void creerComptesTest(){  
    creerCompte(new CompteBancaire("John Lennon", 150000));  
    creerCompte(new CompteBancaire("Paul McCartney", 950000));  
    creerCompte(new CompteBancaire("Ringo Starr", 20000));  
    creerCompte(new CompteBancaire("Georges Harrisson", 100000));  
}
}
